package com.zyh.scs.admin.api.constant.open;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 订单状态 枚举类
 *
 * 内部订单状态(7预受理 8交易成功 9交易失败 10退款成功 11退款失败 12部分退款 13已关闭)
 * 外部订单状态(0待付款 1已付款 2部分退款 3已退款 4支付失败 5已关闭)
 *
 * @author hwh
 */
@Getter
public enum OrderStatus {

    UNKOWN(-999, "", "未知"),

    PRE_PENDING(7, "0", "预受理"),
    TRANS_SUCCESS(8, "1", "交易成功"),
    TRANS_FAIL(9, "5", "交易失败"),
    REFUND_SUCCESS(10, "3", "退款成功"),
    REFUND_FAIL(11, "1", "退款失败"),
    PARTIAL_REFUND(12, "2", "部分退款"),
    CLOSED(13, "5", "已关闭"),
    ;

    private final Integer code;
    private final String outCode;
    private final String desc;

    OrderStatus(Integer code, String outCode, String desc) {
        this.code = code;
        this.outCode = outCode;
        this.desc = desc;
    }

    public static OrderStatus get(Integer code) {
        return Arrays.stream(OrderStatus.values())
                .filter(orderStatus -> Objects.equals(orderStatus.getCode(), code))
                .findFirst().orElse(OrderStatus.UNKOWN);
    }

}